from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-25 14:34:55.917842
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 25, Mar, 2021
Time: 14:35:00
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.1009
Nobs: 241.000 HQIC: -47.8780
Log likelihood: 2844.80 FPE: 9.53552e-22
AIC: -48.4023 Det(Omega_mle): 6.61354e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.447141 0.129591 3.450 0.001
L1.Burgenland 0.072090 0.063962 1.127 0.260
L1.Kärnten -0.215630 0.055347 -3.896 0.000
L1.Niederösterreich 0.086641 0.143131 0.605 0.545
L1.Oberösterreich 0.211788 0.133066 1.592 0.111
L1.Salzburg 0.263696 0.071687 3.678 0.000
L1.Steiermark 0.151544 0.094368 1.606 0.108
L1.Tirol 0.113959 0.062896 1.812 0.070
L1.Vorarlberg -0.034757 0.058586 -0.593 0.553
L1.Wien -0.082936 0.119465 -0.694 0.488
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.481567 0.154904 3.109 0.002
L1.Burgenland 0.005090 0.076456 0.067 0.947
L1.Kärnten 0.336341 0.066158 5.084 0.000
L1.Niederösterreich 0.107119 0.171089 0.626 0.531
L1.Oberösterreich -0.078685 0.159059 -0.495 0.621
L1.Salzburg 0.210983 0.085690 2.462 0.014
L1.Steiermark 0.123352 0.112801 1.094 0.274
L1.Tirol 0.139542 0.075181 1.856 0.063
L1.Vorarlberg 0.159355 0.070030 2.276 0.023
L1.Wien -0.471661 0.142800 -3.303 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.309946 0.062605 4.951 0.000
L1.Burgenland 0.092658 0.030900 2.999 0.003
L1.Kärnten -0.023426 0.026738 -0.876 0.381
L1.Niederösterreich 0.027191 0.069147 0.393 0.694
L1.Oberösterreich 0.307629 0.064284 4.785 0.000
L1.Salzburg 0.013822 0.034632 0.399 0.690
L1.Steiermark 0.005981 0.045589 0.131 0.896
L1.Tirol 0.073824 0.030385 2.430 0.015
L1.Vorarlberg 0.092331 0.028303 3.262 0.001
L1.Wien 0.106690 0.057714 1.849 0.065
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.212311 0.064823 3.275 0.001
L1.Burgenland 0.019780 0.031994 0.618 0.536
L1.Kärnten 0.007927 0.027685 0.286 0.775
L1.Niederösterreich 0.045229 0.071596 0.632 0.528
L1.Oberösterreich 0.401390 0.066561 6.030 0.000
L1.Salzburg 0.082389 0.035859 2.298 0.022
L1.Steiermark 0.138606 0.047204 2.936 0.003
L1.Tirol 0.048491 0.031461 1.541 0.123
L1.Vorarlberg 0.081152 0.029305 2.769 0.006
L1.Wien -0.037291 0.059758 -0.624 0.533
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.520995 0.126440 4.120 0.000
L1.Burgenland 0.080521 0.062407 1.290 0.197
L1.Kärnten 0.006223 0.054001 0.115 0.908
L1.Niederösterreich -0.043276 0.139651 -0.310 0.757
L1.Oberösterreich 0.144221 0.129831 1.111 0.267
L1.Salzburg 0.050773 0.069944 0.726 0.468
L1.Steiermark 0.089481 0.092073 0.972 0.331
L1.Tirol 0.215612 0.061366 3.514 0.000
L1.Vorarlberg 0.037000 0.057162 0.647 0.517
L1.Wien -0.091262 0.116560 -0.783 0.434
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.202523 0.095753 2.115 0.034
L1.Burgenland -0.021590 0.047261 -0.457 0.648
L1.Kärnten -0.027279 0.040895 -0.667 0.505
L1.Niederösterreich -0.053191 0.105758 -0.503 0.615
L1.Oberösterreich 0.445737 0.098321 4.533 0.000
L1.Salzburg 0.003970 0.052969 0.075 0.940
L1.Steiermark -0.018059 0.069727 -0.259 0.796
L1.Tirol 0.166586 0.046473 3.585 0.000
L1.Vorarlberg 0.066873 0.043289 1.545 0.122
L1.Wien 0.241343 0.088271 2.734 0.006
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.244528 0.122379 1.998 0.046
L1.Burgenland 0.019711 0.060402 0.326 0.744
L1.Kärnten -0.061151 0.052267 -1.170 0.242
L1.Niederösterreich -0.053156 0.135166 -0.393 0.694
L1.Oberösterreich 0.006987 0.125661 0.056 0.956
L1.Salzburg 0.076968 0.067698 1.137 0.256
L1.Steiermark 0.346554 0.089116 3.889 0.000
L1.Tirol 0.454883 0.059396 7.659 0.000
L1.Vorarlberg 0.145729 0.055326 2.634 0.008
L1.Wien -0.176053 0.112817 -1.561 0.119
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118698 0.143416 0.828 0.408
L1.Burgenland 0.051129 0.070785 0.722 0.470
L1.Kärnten -0.060412 0.061252 -0.986 0.324
L1.Niederösterreich 0.219759 0.158401 1.387 0.165
L1.Oberösterreich -0.035885 0.147262 -0.244 0.807
L1.Salzburg 0.209800 0.079335 2.644 0.008
L1.Steiermark 0.144100 0.104435 1.380 0.168
L1.Tirol 0.046549 0.069606 0.669 0.504
L1.Vorarlberg 0.086538 0.064836 1.335 0.182
L1.Wien 0.221788 0.132210 1.678 0.093
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.589533 0.078190 7.540 0.000
L1.Burgenland -0.041731 0.038592 -1.081 0.280
L1.Kärnten -0.027319 0.033394 -0.818 0.413
L1.Niederösterreich 0.009034 0.086360 0.105 0.917
L1.Oberösterreich 0.335193 0.080287 4.175 0.000
L1.Salzburg 0.017754 0.043253 0.410 0.681
L1.Steiermark -0.035366 0.056938 -0.621 0.535
L1.Tirol 0.088076 0.037949 2.321 0.020
L1.Vorarlberg 0.114968 0.035348 3.252 0.001
L1.Wien -0.041534 0.072080 -0.576 0.564
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.137189 0.036983 0.160203 0.216297 0.055061 0.075418 -0.003644 0.156930
Kärnten 0.137189 1.000000 0.016154 0.207695 0.175942 -0.073728 0.157216 0.024385 0.306358
Niederösterreich 0.036983 0.016154 1.000000 0.258679 0.057375 0.275817 0.140480 0.041954 0.305329
Oberösterreich 0.160203 0.207695 0.258679 1.000000 0.302739 0.285039 0.086277 0.053483 0.135836
Salzburg 0.216297 0.175942 0.057375 0.302739 1.000000 0.147521 0.048544 0.097751 -0.002563
Steiermark 0.055061 -0.073728 0.275817 0.285039 0.147521 1.000000 0.112070 0.113893 -0.134379
Tirol 0.075418 0.157216 0.140480 0.086277 0.048544 0.112070 1.000000 0.163836 0.147778
Vorarlberg -0.003644 0.024385 0.041954 0.053483 0.097751 0.113893 0.163836 1.000000 0.002921
Wien 0.156930 0.306358 0.305329 0.135836 -0.002563 -0.134379 0.147778 0.002921 1.000000